

package controller;




import bo.BUS_HoaDon;
import bo.BUS_SanPham;
import com.opensymphony.xwork2.ActionSupport;
import dto.DTO_KhachHang;
import dto.DTO_SanPham;
import java.text.Format;
import java.util.ArrayList;



public class QLThongKeAction extends ActionSupport {

    private int tongdoanhthu;
    private int tongsanphamban;
    private String TenSP;
    private String MaSP;
    private int DoanhThu;
    private int sl;

    public int getSl() {
        return sl;
    }

    public void setSl(int sl) {
        this.sl = sl;
    }

    public ArrayList<dto.DTO_KhachHang> dskh;

    public ArrayList<DTO_KhachHang> getDskh() {
        return dskh;
    }

    public void setDskh(ArrayList<DTO_KhachHang> dskh) {
        this.dskh = dskh;
    }

    ArrayList<dto.DTO_SanPham> dsbc;

    public int getTongsanphamban() {
        return tongsanphamban;
    }

    public void setTongsanphamban(int tongsanphamban) {
        this.tongsanphamban = tongsanphamban;
    }

    public ArrayList<DTO_SanPham> getDsbc() {
        return dsbc;
    }

    public void setDsbc(ArrayList<DTO_SanPham> dsbc) {
        this.dsbc = dsbc;
    }

    public int getDoanhThu() {
        return DoanhThu;
    }

    public void setDoanhThu(int DoanhThu) {
        this.DoanhThu = DoanhThu;
    }

    public String getMaSP() {
        return MaSP;
    }

    public void setMaSP(String MaSP) {
        this.MaSP = MaSP;
    }


    public String getTenSP() {
        return TenSP;
    }

    public void setTenSP(String TenSP) {
        this.TenSP = TenSP;
    }

    public int getTongdoanhthu() {
        return tongdoanhthu;
    }

    public void setTongdoanhthu(int tongdoanhthu) {
        this.tongdoanhthu = tongdoanhthu;
    }


    public QLThongKeAction() {
        tongdoanhthu =0;
        sl = 5;
    }



    public String execute() throws Exception {
        BUS_HoaDon bus = new BUS_HoaDon();
        tongdoanhthu = bus.TongDoanhThu();
        tongsanphamban = bus.tongsanphamban();
        
        dsbc = bus.dsBanChay(sl);
        for(int i =0;i<dsbc.size();i++)
        {
            DTO_SanPham sp = new DTO_SanPham();
            sp = (DTO_SanPham)dsbc.get(i);
            float phantram = ((float)sp.getDoanhthu()/tongdoanhthu)* 100;

            String s = String.format("%.2f",phantram);
            sp.setPhantran(Float.parseFloat(s));
            dsbc.remove(i);
            dsbc.add(i, sp);
        }
        dskh = bus.dskhahhang(sl);
        return ("success");
    }



}